package com.hsav.kcxb.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hsav.kcxb.R;
import com.hsav.kcxb.bean.PlayRemarkBean;
import com.hsav.kcxb.utils.ImgLoadUtil;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;

/**
 * Created by zhao on 2017/2/4.
 */

public class PlayRemarkAdapter extends BaseAdapter {

    private final Context mContext;
    private final LayoutInflater mLayoutInflater;
    private final ArrayList<PlayRemarkBean> mRemarkList;

    public PlayRemarkAdapter(Context context, ArrayList<PlayRemarkBean> remarkBeanArrayList) {
        this.mContext = context;
        this.mLayoutInflater = LayoutInflater.from(context);
        this.mRemarkList = remarkBeanArrayList;
    }

    @Override
    public int getCount() {
        if(mRemarkList!=null){
            return mRemarkList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if(mRemarkList!=null){
            return mRemarkList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder = null;
        if(convertView==null){
            convertView = mLayoutInflater.inflate(R.layout.item_remark_view,parent,false);
            myViewHolder = new MyViewHolder();
            myViewHolder.headImg = (ImageView)convertView.findViewById(R.id.iv_remark_head);
            myViewHolder.likeImg = (ImageView)convertView.findViewById(R.id.iv_remark_like);
            myViewHolder.contentTx = (TextView)convertView.findViewById(R.id.tv_remark_content);
            myViewHolder.nameTx = (TextView)convertView.findViewById(R.id.tv_remark_name);
            myViewHolder.dateTx = (TextView)convertView.findViewById(R.id.tv_remark_date);
            convertView.setTag(myViewHolder);
            AutoUtils.autoSize(convertView);
        }else{
            myViewHolder = (MyViewHolder)convertView.getTag();
        }
        PlayRemarkBean playRemarkBean = (PlayRemarkBean) getItem(position);
        if(playRemarkBean!=null){
            myViewHolder.contentTx.setText(playRemarkBean.getRemark());
            myViewHolder.nameTx.setText(playRemarkBean.getUserName());
            myViewHolder.dateTx.setText(playRemarkBean.getRemarkDate());
            ImgLoadUtil.setImage(mContext,myViewHolder.headImg,playRemarkBean.getPicture(),R.drawable.head);
        }
        return convertView;
    }

    private class MyViewHolder{
        ImageView headImg;
        ImageView likeImg;
        TextView nameTx;
        TextView contentTx;
        TextView dateTx;
    }
}
